package cn.edu.cqvie.jdk8.stream;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest4 {

    public static void main(String[] args) {
//        Stream<String> stream = Stream.of("hello", "world", "hello world");
//        String[] strings = stream.toArray(len -> new String[len]);
//        String[] strings = stream.toArray(String[]::new);
//        Arrays.asList(strings).forEach(System.out::println);

//        Stream<String> stream = Stream.of("hello", "world", "hello world");
//将流转换为List
//List<String> list = stream.collect(Collectors.toList());

//List<String> list = stream.collect(()-> new ArrayList<String>(), (li, item) -> li.add(item), (li1, li2) -> li1.addAll(li2));

//        List<String> list = stream.collect(
//                //返回结果
//                LinkedList::new,
//                //累加器
//                LinkedList::add,
//                //合并器,上次得到的每个List放入最终的List
//                LinkedList::addAll);
//
//        list.forEach(System.out::println);


//        Stream<String> stream = Stream.of("hello", "world", "hello world");
//        List<String> list = stream.collect(Collectors.toCollection(LinkedList::new));
//        list.forEach(System.out::println);


//        Stream<String> stream = Stream.of("hello", "world", "hello world");
//        Set<String> set = stream.collect(Collectors.toCollection(TreeSet::new));
//        set.forEach(System.out::println);


        Stream<String> stream = Stream.of("hello", "world", "hello world");
        String str = stream.collect(Collectors.joining(" "));
        System.out.println(str);
    }
}
